import { DynamicModule, Type } from '@nestjs/common'
import { RouterModule } from '@nestjs/core'
import { FLOW_ROUTER_PREFIX } from '../app-const'

/**
 * 注册路由模块
 * @param routes
 * @returns
 */
export function registerRouterModule(modules: Type[], prefixPath?: string): Array<DynamicModule | Type> {
  return [
    RouterModule.register(
      modules.map(module => {
        return {
          path: FLOW_ROUTER_PREFIX + (prefixPath ? `/${prefixPath}` : ''),
          module,
        }
      })
    ),
    ...modules,
  ]
}
